# -*- coding: utf-8 -*-
import cv2
# import matplotlib.pyplot as plt
from main_gui import EasyImageProcessingToolkit
import wx
import wx.xrc
import tkinter as tk
from tkinter import filedialog
# from PIL import Image, ImageTk
from create_zoom_window import *
from create_hist_window import *
import windnd
import sys
from algo_pack import image_filter
# cv 2 pil
# im_pil = Image.fromarray(im_cv)
# pil 2 cv
# im_cv = np.asarray(im_pil)

# # self.icon = wx.Icon(name="C:/Users/admin/Desktop/testGUI/bb.png", type=wx.BITMAP_TYPE_PNG)
# self.icon = wx.Icon(name="./pic/bb.png", type=wx.BITMAP_TYPE_PNG)
# self.SetIcon(self.icon)
# self.Show(True)

class RunIPT(EasyImageProcessingToolkit, Zoom_Advanced):
	def __init__(self, parent):
		EasyImageProcessingToolkit.__init__(self, parent)
		self.icon = wx.Icon(name="./pic/logo.png", type=wx.BITMAP_TYPE_PNG)
		self.SetIcon(self.icon)
		self.Show(True)
		self.image_open = None
		self.image_current = None
		self.image_bgr = None
		self.image_rgb = None
		self.image_lab = None
		self.image_ycrcb = None
		self.image_gray = None
		self.image_binary = None
		self.image_invert = None
		self.image_filter = None
		self.image_edge = None
		self.image_morph = None
		self.image_rotate = None
		self.image_flip = None
		self.image_resize = None
		self.image_contrast = None
		self.image_skeleton = None
		self.image_blob = None
		self.image_hough = None
		self.image_proj = None

		self.tk_create_drop_obj = None
		self.tk_create_show_window_obj = None
		self.show_obj = None
		self.is_create_toplevel = False  # 用来判断是否建立过TopLevel对象
		self.activate_algo_flag = 0
		self.activate_algo_flag_dict = {"image_binary": 1,
										"image_filter": 2,
										"image_edge": 3,
										"image_morph": 4,
										"image_rotate": 5,
										"image_flip": 6,
										"image_resize": 7,
										"image_contrast": 8,
										"image_skeleton": 9,
										"image_blob": 10,
										"image_hough": 11,
										"image_proj": 12,
										"image_template_match": 13}


	@staticmethod
	def message_box(box_title_, message_text_):
		tk_message_obj = tk.Tk()
		tk_message_obj.withdraw()
		tk_message_obj.update()
		tk.messagebox.showinfo(box_title_, message_text_)
		tk_message_obj.destroy()

	@staticmethod
	def show_image(input_image_):
		cv2.imshow("Show oringinal image", input_image_)
		cv2.waitKey(0)

	def assign_current_image(self):
		# 下方如果某个标志flag被置为数字，就会把对应数字所代表的算子运行结果赋值给对应的类属性，因为类属性无法在创建窗口类中获取变量
		if self.activate_algo_flag == 1:
			self.image_binary = np.array(self.show_obj.image_binary_cv)
			self.image_current = np.array(self.image_binary)
		elif self.activate_algo_flag == 2:
			self.image_filter = np.array(self.show_obj.image_filter_cv)
			self.image_current = np.array(self.image_filter)
		elif self.activate_algo_flag == 3:
			self.image_edge = np.array(self.show_obj.image_edge_cv)
			self.image_current = np.array(self.image_edge)
		elif self.activate_algo_flag == 4:
			self.image_morph = np.array(self.show_obj.image_morph_cv)
			self.image_current = np.array(self.image_morph)
		elif self.activate_algo_flag == 5:
			self.image_rotate = np.array(self.show_obj.image_rotate_cv)
			self.image_current = np.array(self.image_rotate)
		elif self.activate_algo_flag == 6:
			self.image_flip = np.array(self.show_obj.image_flip_cv)
			self.image_current = np.array(self.image_flip)
		elif self.activate_algo_flag == 7:
			self.image_resize = np.array(self.show_obj.image_resize_cv)
			self.image_current = np.array(self.image_resize)
		elif self.activate_algo_flag == 8:
			self.image_contrast = np.array(self.show_obj.image_contrast_cv)
			self.image_current = np.array(self.image_contrast)
		elif self.activate_algo_flag == 9:
			self.image_skeleton = np.array(self.show_obj.image_skeleton_cv)
			self.image_current = np.array(self.image_skeleton)
		elif self.activate_algo_flag == 10:
			self.image_blob = np.array(self.show_obj.image_blob_cv)
			self.image_current = np.array(self.image_blob)

		self.activate_algo_flag = 0

	# 创建"图像转换"显示窗口
	def create_transf_win(self, show_win_str):
		# 如果从来没有创建过窗口，那么就创建一次
		if self.is_create_toplevel is False:
			self.tk_create_show_window_obj = tk.Toplevel()
			self.is_create_toplevel = True
		# 如果手动关闭当前窗口，这时，is_create_topLevel仍然是True,所以需要通过判断是否存在topLevel对象，决定是否需要重新构造对象
		if self.is_create_toplevel is True and self.tk_create_show_window_obj.winfo_exists() == 0:
			self.tk_create_show_window_obj = tk.Toplevel()
		# 创建显示窗口（带缩放功能），从而显示“当前图像”
		self.show_obj = Zoom_Advanced(self.tk_create_show_window_obj, self.image_current, show_win_str)
		self.show_obj.show_image()
		self.tk_create_show_window_obj.protocol('WM_DELETE_WINDOW', self.show_obj.close_win)
		self.tk_create_show_window_obj.mainloop()

	def dragged_files(self, files):
		self.tk_create_drop_obj.withdraw()
		current_file_path = '\n'.join((item.decode('gbk') for item in files))
		# self.image_open = cv2.imread(current_file_path)
		self.image_open = cv2.imdecode(np.fromfile(current_file_path, dtype=np.uint8), -1)
		if self.image_open is None:
			box_title, message_text = "Warning", "Sorry, no image found..."
			self.message_box(box_title, message_text)
		else:
			self.image_current = np.array(self.image_open)
			self.tk_create_drop_obj = tk.Toplevel()
			self.show_obj = Zoom_Advanced(self.tk_create_drop_obj, self.image_current, "Show oringinal image")
			self.show_obj.show_image()
			self.tk_create_drop_obj.protocol('WM_DELETE_WINDOW', self.show_obj.close_win)
			self.tk_create_drop_obj.mainloop()

	# ------------- 文件拖拽功能 ------------------
	def tool_drop(self, event):
		self.tk_create_drop_obj = tk.Tk()
		windnd.hook_dropfiles(self.tk_create_drop_obj, func=self.dragged_files)
		self.tk_create_drop_obj.mainloop()

	def item_quick_open(self, event):
		self.open_file(event)

	# ------------- Menu： 文件 ------------------
	def open_file(self, event):
		tk_open_obj = tk.Tk()
		tk_open_obj.withdraw()
		image_file_path = filedialog.askopenfilename()     # 只能打开单个文件
		# image_file_paths = filedialog.askopenfilenames() # 支持打开多个文件
		print(image_file_path)
		# self.image_open = cv2.imread(image_file_path)
		self.image_open = cv2.imdecode(np.fromfile(image_file_path, dtype=np.uint8), -1)
		if self.image_open is not None:
			self.image_current = np.array(self.image_open)
			# 如果从来没有创建过窗口，那么就创建一次
			tk_open_obj = tk.Toplevel()
			# 创建显示窗口（带缩放功能），从而显示“当前图像”
			show_open_obj = Zoom_Advanced(tk_open_obj, self.image_current, "Show oringinal image")
			show_open_obj.show_image()
			tk_open_obj.protocol('WM_DELETE_WINDOW', show_open_obj.close_win)
			tk_open_obj.mainloop()

	def save_as(self, event):
		if self.image_current is None:
			box_title, message_text = "Warning", "Sorry, no image to save..."
			self.message_box(box_title, message_text)
		else:
			image_file_path = filedialog.asksaveasfilename(defaultextension='.bmp', filetypes=[("Image files", ".bmp")])
			cv2.imwrite(image_file_path, self.image_current)

	def exit_win(self, event):
		sys.exit(0)

	# ------------- Menu： 变换 ------------------
	def image_rotate(self, event):
		# 如果上一步操作是带有捆绑事件的类函数，在这里把类属性赋值给image_current这个变量
		self.assign_current_image()
		if self.image_current is None:
			box_title, message_text = "Warning", "Sorry, no image found..."
			self.message_box(box_title, message_text)
		else:
			# 如果从来没有创建过窗口，那么就创建一次
			if self.is_create_toplevel is False:
				self.tk_create_show_window_obj = tk.Toplevel()
				self.is_create_toplevel = True
			# 如果手动关闭当前窗口，这时，is_create_topLevel仍然是True,所以需要通过判断是否存在topLevel对象，
			# 决定是否需要重新构造对象
			if self.is_create_toplevel is True and self.tk_create_show_window_obj.winfo_exists() == 0:
				self.tk_create_show_window_obj = tk.Toplevel()
				self.image_current = self.image_open

			self.show_obj = Zoom_Advanced(self.tk_create_show_window_obj, self.image_current, "Result: Image rotate")
			self.show_obj.show_image()
			self.show_obj.rotate_operate()
			self.tk_create_show_window_obj.protocol('WM_DELETE_WINDOW', self.show_obj.close_win)
			self.activate_algo_flag = self.activate_algo_flag_dict['image_rotate']
			self.tk_create_show_window_obj.mainloop()

	def image_flip(self, event):
		# 如果上一步操作是带有捆绑时间的类函数，在这里把类属性赋值给image_current这个变量
		self.assign_current_image()
		if self.image_current is None:
			box_title, message_text = "Warning", "Sorry, no image found..."
			self.message_box(box_title, message_text)
		else:
			# 如果从来没有创建过窗口，那么就创建一次
			if self.is_create_toplevel is False:
				self.tk_create_show_window_obj = tk.Toplevel()
				self.is_create_toplevel = True
			# 如果手动关闭当前窗口，这时，is_create_topLevel仍然是True,所以需要通过判断是否存在topLevel对象，
			# 决定是否需要重新构造对象
			if self.is_create_toplevel is True and self.tk_create_show_window_obj.winfo_exists() == 0:
				self.tk_create_show_window_obj = tk.Toplevel()
				self.image_current = self.image_open

			self.show_obj = Zoom_Advanced(self.tk_create_show_window_obj, self.image_current, "Result: Image flip")
			self.show_obj.show_image()
			self.show_obj.flip_operate()
			self.tk_create_show_window_obj.protocol('WM_DELETE_WINDOW', self.show_obj.close_win)
			self.activate_algo_flag = self.activate_algo_flag_dict['image_flip']
			self.tk_create_show_window_obj.mainloop()

	def image_resize(self, event):
		# 如果上一步操作是带有捆绑时间的类函数，在这里把类属性赋值给image_current这个变量
		self.assign_current_image()
		if self.image_current is None:
			box_title, message_text = "Warning", "Sorry, no image found..."
			self.message_box(box_title, message_text)
		else:
			# 如果从来没有创建过窗口，那么就创建一次
			if self.is_create_toplevel is False:
				self.tk_create_show_window_obj = tk.Toplevel()
				self.is_create_toplevel = True
			# 如果手动关闭当前窗口，这时，is_create_topLevel仍然是True,所以需要通过判断是否存在topLevel对象，
			# 决定是否需要重新构造对象
			if self.is_create_toplevel is True and self.tk_create_show_window_obj.winfo_exists() == 0:
				self.tk_create_show_window_obj = tk.Toplevel()
				self.image_current = self.image_open

			self.show_obj = Zoom_Advanced(self.tk_create_show_window_obj, self.image_current, "Result: Image resize")
			self.show_obj.show_image()
			self.show_obj.resize_operate()
			self.tk_create_show_window_obj.protocol('WM_DELETE_WINDOW', self.show_obj.close_win)
			self.activate_algo_flag = self.activate_algo_flag_dict['image_resize']
			self.tk_create_show_window_obj.mainloop()

	# ------------- Menu： 颜色 ------------------
	def bgr_2_rgb(self, event):
		# 如果上一步操作是带有捆绑时间的类函数，在这里把类属性赋值给image_current这个变量
		self.assign_current_image()
		# 如果关闭了显示转换图像的窗口， 那么重新初始化current图像，否则它仍会保留关闭 前的历史结果。
		if self.tk_create_show_window_obj is not None and self.tk_create_show_window_obj.winfo_exists() == 0:
			self.image_current = self.image_open
		if self.image_current is None:
			box_title, message_text = "Warning", "Sorry, bgr image not found..."
			self.message_box(box_title, message_text)
		elif self.image_current.ndim != 3:
			box_title, message_text = "Warning", "Sorry, image not 3 channels..."
			self.message_box(box_title, message_text)
		else:
			self.image_rgb = cv2.cvtColor(self.image_current, cv2.COLOR_BGR2RGB)
			self.image_current = np.array(self.image_rgb)
			self.create_transf_win("Result: BGR -> RGB")

	def gray_2_bgr(self, event):
		# 如果上一步操作是带有捆绑时间的类函数，在这里把类属性赋值给image_current这个变量
		self.assign_current_image()
		# 如果关闭了显示转换图像的窗口， 那么重新初始化current图像，否则它仍会保留关闭 前的历史结果。
		if self.tk_create_show_window_obj is not None and self.tk_create_show_window_obj.winfo_exists() == 0:
			self.image_current = self.image_open
		if self.image_current is None:
			box_title, message_text = "Warning", "Sorry, gray image not found..."
			self.message_box(box_title, message_text)
		elif self.image_current.ndim != 2:
			box_title, message_text = "Warning", "Sorry, image not single channel..."
			self.message_box(box_title, message_text)
		else:
			self.image_bgr = cv2.cvtColor(self.image_current, cv2.COLOR_GRAY2BGR)
			self.image_current = np.array(self.image_bgr)
			self.create_transf_win("Result: Gray -> BGR")

	def bgr_2_gray(self, event):
		# 如果上一步操作是带有捆绑时间的类函数，在这里把类属性赋值给image_current这个变量
		self.assign_current_image()
		# 如果关闭了显示转换图像的窗口， 那么重新初始化current图像，否则它仍会保留关闭 前的历史结果。
		if self.tk_create_show_window_obj is not None and self.tk_create_show_window_obj.winfo_exists() == 0:
			self.image_current = self.image_open
		if self.image_current is None:
			box_title, message_text = "Warning", "Sorry, bgr image not found..."
			self.message_box(box_title, message_text)
		elif self.image_current.ndim != 3:
			box_title, message_text = "Warning", "Sorry, image not 3 channels..."
			self.message_box(box_title, message_text)
		else:
			self.image_gray = cv2.cvtColor(self.image_current, cv2.COLOR_BGR2GRAY)
			self.image_current = np.array(self.image_gray)
			self.create_transf_win("Result: BGR -> Gray")

	def bgr_2_lab(self, event):
		# 如果上一步操作是带有捆绑时间的类函数，在这里把类属性赋值给image_current这个变量
		self.assign_current_image()
		# 如果关闭了显示转换图像的窗口， 那么重新初始化current图像，否则它仍会保留关闭 前的历史结果。
		if self.tk_create_show_window_obj is not None and self.tk_create_show_window_obj.winfo_exists() == 0:
			self.image_current = self.image_open
		if self.image_current is None:
			box_title, message_text = "Warning", "Sorry, bgr image not found..."
			self.message_box(box_title, message_text)
		elif self.image_current.ndim != 3:
			box_title, message_text = "Warning", "Sorry, image not 3 channels..."
			self.message_box(box_title, message_text)
		else:
			self.image_lab = cv2.cvtColor(self.image_current, cv2.COLOR_BGR2LAB)
			self.image_current = np.array(self.image_lab)
			self.create_transf_win("Result: BGR -> Lab")

	def bgr_2_YCrCb(self, event):
		# 如果上一步操作是带有捆绑时间的类函数，在这里把类属性赋值给image_current这个变量
		self.assign_current_image()
		# 如果关闭了显示转换图像的窗口， 那么重新初始化current图像，否则它仍会保留关闭 前的历史结果。
		if self.tk_create_show_window_obj is not None and self.tk_create_show_window_obj.winfo_exists() == 0:
			self.image_current = self.image_open
		if self.image_current is None:
			box_title, message_text = "Warning", "Sorry, bgr image not found..."
			self.message_box(box_title, message_text)
		elif self.image_current.ndim != 3:
			box_title, message_text = "Warning", "Sorry, image not 3 channels..."
			self.message_box(box_title, message_text)
		else:
			self.image_ycrcb = cv2.cvtColor(self.image_current, cv2.COLOR_BGR2YCrCb)
			self.image_current = np.array(self.image_ycrcb)
			self.create_transf_win("Result: BGR -> YCrCb")

	def binarization(self, event):
		# 如果上一步操作是带有捆绑时间的类函数，在这里把类属性赋值给image_current这个变量
		self.assign_current_image()
		if self.image_current is None:
			box_title, message_text = "Warning", "Sorry, no image found..."
			self.message_box(box_title, message_text)
		else:
			# 如果从来没有创建过窗口，那么就创建一次
			if self.is_create_toplevel is False:
				self.tk_create_show_window_obj = tk.Toplevel()
				self.is_create_toplevel = True
			# 如果手动关闭当前窗口，这时，is_create_topLevel仍然是True,所以需要通过判断是否存在topLevel对象，
			# 决定是否需要重新构造对象
			if self.is_create_toplevel is True and self.tk_create_show_window_obj.winfo_exists() == 0:
				self.tk_create_show_window_obj = tk.Toplevel()
				self.image_current = self.image_open

			self.show_obj = Zoom_Advanced(self.tk_create_show_window_obj, self.image_current, "Result: Image binaire")
			self.show_obj.show_image()
			self.show_obj.binary_operate()
			self.tk_create_show_window_obj.protocol('WM_DELETE_WINDOW', self.show_obj.close_win)
			self.activate_algo_flag = self.activate_algo_flag_dict['image_binary']
			self.tk_create_show_window_obj.mainloop()

	def histogram(self, event):
		if self.image_current is None:
			box_title, message_text = "Warning", "Sorry, no image found..."
			self.message_box(box_title, message_text)
		else:
			root = tk.Tk()
			hist_obj = Hist_window(root, self.image_current, "Result: Histogram")
			root.protocol('WM_DELETE_WINDOW', hist_obj.close_win)
			root.mainloop()

	def gray_image_invert(self, event):
		# 如果上一步操作是带有捆绑时间的类函数，在这里把类属性赋值给image_current这个变量
		self.assign_current_image()
		# 如果关闭了显示转换图像的窗口， 那么重新初始化current图像，否则它仍会保留关闭 前的历史结果。
		if self.tk_create_show_window_obj is not None and self.tk_create_show_window_obj.winfo_exists() == 0:
			self.image_current = self.image_open
		if self.image_current is None:
			box_title, message_text = "Warning", "Sorry, no image found..."
			self.message_box(box_title, message_text)
		elif self.image_current.ndim != 2:
			box_title, message_text = "Warning", "Sorry, image not single channels..."
			self.message_box(box_title, message_text)
		else:
			self.image_invert = 255 - self.image_current
			self.image_current = np.array(self.image_invert)
			self.create_transf_win("Result: Invert")

	def image_contrast(self, event):
		# 如果上一步操作是带有捆绑时间的类函数，在这里把类属性赋值给image_current这个变量
		self.assign_current_image()
		if self.image_current is None:
			box_title, message_text = "Warning", "Sorry, no image found..."
			self.message_box(box_title, message_text)
		else:
			# 如果从来没有创建过窗口，那么就创建一次
			if self.is_create_toplevel is False:
				self.tk_create_show_window_obj = tk.Toplevel()
				self.is_create_toplevel = True
			# 如果手动关闭当前窗口，这时，is_create_topLevel仍然是True,所以需要通过判断是否存在topLevel对象，
			# 决定是否需要重新构造对象
			if self.is_create_toplevel is True and self.tk_create_show_window_obj.winfo_exists() == 0:
				self.tk_create_show_window_obj = tk.Toplevel()
				self.image_current = self.image_open
			self.show_obj = Zoom_Advanced(self.tk_create_show_window_obj, self.image_current, "Result: Image contrast")
			self.show_obj.show_image()
			self.show_obj.contrast_operate()
			self.tk_create_show_window_obj.protocol('WM_DELETE_WINDOW', self.show_obj.close_win)
			self.activate_algo_flag = self.activate_algo_flag_dict['image_contrast']
			self.tk_create_show_window_obj.mainloop()

	# ------------- Menu： 滤波 ------------------
	def image_filter(self, event):
		# 如果上一步操作是带有捆绑时间的类函数，在这里把类属性赋值给image_current这个变量
		self.assign_current_image()
		if self.image_current is None:
			box_title, message_text = "Warning", "Sorry, no image found..."
			self.message_box(box_title, message_text)
		else:
			# 如果从来没有创建过窗口，那么就创建一次
			if self.is_create_toplevel is False:
				self.tk_create_show_window_obj = tk.Toplevel()
				self.is_create_toplevel = True
			# 如果手动关闭当前窗口，这时，is_create_topLevel仍然是True,所以需要通过判断是否存在topLevel对象，
			# 决定是否需要重新构造对象
			if self.is_create_toplevel is True and self.tk_create_show_window_obj.winfo_exists() == 0:
				self.tk_create_show_window_obj = tk.Toplevel()
				self.image_current = self.image_open
			self.show_obj = Zoom_Advanced(self.tk_create_show_window_obj, self.image_current, "Result: Image filter")
			self.show_obj.show_image()
			self.show_obj.filter_operate()
			self.tk_create_show_window_obj.protocol('WM_DELETE_WINDOW', self.show_obj.close_win)
			self.activate_algo_flag = self.activate_algo_flag_dict['image_filter']
			self.tk_create_show_window_obj.mainloop()

	def image_edge(self, event):
		# 如果上一步操作是带有捆绑时间的类函数，在这里把类属性赋值给image_current这个变量
		self.assign_current_image()
		if self.image_current is None:
			box_title, message_text = "Warning", "Sorry, no image found..."
			self.message_box(box_title, message_text)
		else:
			# 如果从来没有创建过窗口，那么就创建一次
			if self.is_create_toplevel is False:
				self.tk_create_show_window_obj = tk.Toplevel()
				self.is_create_toplevel = True
			# 如果手动关闭当前窗口，这时，is_create_topLevel仍然是True,所以需要通过判断是否存在topLevel对象，
			# 决定是否需要重新构造对象
			if self.is_create_toplevel is True and self.tk_create_show_window_obj.winfo_exists() == 0:
				self.tk_create_show_window_obj = tk.Toplevel()
				self.image_current = self.image_open
			self.show_obj = Zoom_Advanced(self.tk_create_show_window_obj, self.image_current, "Result: Image edge")
			self.show_obj.show_image()
			self.show_obj.edge_operate()
			self.tk_create_show_window_obj.protocol('WM_DELETE_WINDOW', self.show_obj.close_win)
			self.activate_algo_flag = self.activate_algo_flag_dict['image_edge']
			self.tk_create_show_window_obj.mainloop()

	def image_morph(self, event):
		# 如果上一步操作是带有捆绑时间的类函数，在这里把类属性赋值给image_current这个变量
		self.assign_current_image()
		if self.image_current is None:
			box_title, message_text = "Warning", "Sorry, no image found..."
			self.message_box(box_title, message_text)
		else:
			# 如果从来没有创建过窗口，那么就创建一次
			if self.is_create_toplevel is False:
				self.tk_create_show_window_obj = tk.Toplevel()
				self.is_create_toplevel = True
			# 如果手动关闭当前窗口，这时，is_create_topLevel仍然是True,所以需要通过判断是否存在topLevel对象，
			# 决定是否需要重新构造对象
			if self.is_create_toplevel is True and self.tk_create_show_window_obj.winfo_exists() == 0:
				self.tk_create_show_window_obj = tk.Toplevel()
				self.image_current = self.image_open
			self.show_obj = Zoom_Advanced(self.tk_create_show_window_obj, self.image_current, "Result: Image morph")
			self.show_obj.show_image()
			self.show_obj.morph_operate()
			self.tk_create_show_window_obj.protocol('WM_DELETE_WINDOW', self.show_obj.close_win)
			self.activate_algo_flag = self.activate_algo_flag_dict['image_morph']
			self.tk_create_show_window_obj.mainloop()

	def image_skeleton(self, event):
		# 如果上一步操作是带有捆绑时间的类函数，在这里把类属性赋值给image_current这个变量
		self.assign_current_image()
		if self.image_current is None:
			box_title, message_text = "Warning", "Sorry, no image found..."
			self.message_box(box_title, message_text)
		else:
			# 如果从来没有创建过窗口，那么就创建一次
			if self.is_create_toplevel is False:
				self.tk_create_show_window_obj = tk.Toplevel()
				self.is_create_toplevel = True
			# 如果手动关闭当前窗口，这时，is_create_topLevel仍然是True,所以需要通过判断是否存在topLevel对象，
			# 决定是否需要重新构造对象
			if self.is_create_toplevel is True and self.tk_create_show_window_obj.winfo_exists() == 0:
				self.tk_create_show_window_obj = tk.Toplevel()
				self.image_current = self.image_open
			self.show_obj = Zoom_Advanced(self.tk_create_show_window_obj, self.image_current, "Result: Image skeleton")
			self.show_obj.show_image()
			self.show_obj.skeleton_operate()
			self.tk_create_show_window_obj.protocol('WM_DELETE_WINDOW', self.show_obj.close_win)
			self.activate_algo_flag = self.activate_algo_flag_dict['image_skeleton']
			self.tk_create_show_window_obj.mainloop()

	def image_blob(self, event):
		# 如果上一步操作是带有捆绑时间的类函数，在这里把类属性赋值给image_current这个变量
		self.assign_current_image()
		if self.image_current is None:
			box_title, message_text = "Warning", "Sorry, no image found..."
			self.message_box(box_title, message_text)
		else:
			# 如果从来没有创建过窗口，那么就创建一次
			if self.is_create_toplevel is False:
				self.tk_create_show_window_obj = tk.Toplevel()
				self.is_create_toplevel = True
			# 如果手动关闭当前窗口，这时，is_create_topLevel仍然是True,所以需要通过判断是否存在topLevel对象，
			# 决定是否需要重新构造对象
			if self.is_create_toplevel is True and self.tk_create_show_window_obj.winfo_exists() == 0:
				self.tk_create_show_window_obj = tk.Toplevel()
				self.image_current = self.image_open
			self.show_obj = Zoom_Advanced(self.tk_create_show_window_obj, self.image_current, "Result: Image blob")
			self.show_obj.show_image()
			self.show_obj.blob_operate()
			self.tk_create_show_window_obj.protocol('WM_DELETE_WINDOW', self.show_obj.close_win)
			self.activate_algo_flag = self.activate_algo_flag_dict['image_blob']
			self.tk_create_show_window_obj.mainloop()




	def version_description(self, event):
		win = tk.Tk()
		win.title('软件信息')
		# win.geometry('400x400')
		text = tk.Text(win, width=50, height=25)
		scroll = tk.Scrollbar()
		# 放到窗口的右侧, 填充Y竖直方向
		scroll.pack(side=tk.RIGHT, fill=tk.Y)
		# 两个控件关联
		scroll.config(command=text.yview)
		text.config(yscrollcommand=scroll.set)
		text.pack()
		description_text = 'Operating System: win10\n' \
						   'Version: beta\n' \
						   'Software: Easy Image Process Toolkit\n' \
						   'Author: C.C \n' \
						   'Company: C & W \n' \
						   'Plug-ins: \n' \
						   '变换： 旋转(顺时针，逆时针)\n' \
						   '      镜像(水平， 垂直)\n' \
						   '      缩放\n' \
						   '           -> 双线性\n' \
						   '           -> 最近邻\n' \
						   '           -> 立方\n' \
						   '           -> 面积差值\n' \
						   '           -> 兰索斯差值\n' \
						   '\n' \
						   '颜色:  BGR -> RGB\n' \
						   '      GRAY -> BGR\n' \
						   '      BGR -> GRAY\n' \
						   '      BGR -> LAB\n' \
						   '      BGR -> YCrCb\n' \
						   '      二值化\n' \
						   '           -> 手动二值化\n' \
						   '           -> 自适应二值化\n' \
						   '           -> OTSU二值化\n' \
						   '           -> SAUVOLA二值化\n' \
						   '           -> NIBLACK二值化\n' \
						   '      直方图\n' \
						   '      反向\n' \
						   '      对比度拉伸\n' \
						   '           -> 线性拉伸\n' \
						   '           -> 直方归一化\n' \
						   '           -> gamma矫正\n' \
						   '           -> 全局直方图均衡化\n' \
						   '           -> CLAHE均衡化\n' \
						   '\n' \
						   '滤波： 图像滤波\n' \
						   '           -> 高斯滤波 \n' \
						   '           -> 均值滤波 \n' \
						   '           -> 中值滤波 \n' \
						   '           -> 双边滤波 \n' \
						   '      边缘检测\n' \
						   '           -> Laplacian梯度 \n' \
						   '           -> Sobel边缘 \n' \
						   '           -> Prewitt边缘 \n' \
						   '           -> Roberts边缘 \n' \
						   '           -> Canny边缘 \n' \
						   '           -> LoG边缘 \n' \
						   '      形态学滤波\n' \
						   '           -> 腐蚀操作 \n' \
						   '           -> 膨胀操作 \n' \
						   '           -> 开运算 \n' \
						   '           -> 闭运算 \n' \
						   '      骨架提取(skeletonize, medial_axis)\n'

		text.insert(tk.INSERT, description_text)
		win.mainloop()







if __name__ == '__main__':
	app = wx.App(False)
	ipt = RunIPT(None)
	ipt.Show(True)
	app.MainLoop()
	sys.exit(0)
